﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace benefit.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            Benefit.ViewModel.SystemVersion version = new Benefit.ViewModel.SystemVersion();
            return View(version);
        }
        [HttpPost]
        public ActionResult Index(string pUserName, string pPassword)
        {
            BenefitHelper.DB.DBManager db = new BenefitHelper.DB.DBManager();
            BenefitHelper.Sys.User user = new BenefitHelper.Sys.User();

            BenefitHelper.Sys.TradeHistory th = new BenefitHelper.Sys.TradeHistory();
            string pdate = th.GetLastTradeHistoryDateString(db);
            if (!string.IsNullOrEmpty(pdate))
            {
                int tid = th.GetLastTradeHistoryId(db);
                if (tid != 0)
                {
                    //  pdate.Debug();
                    int[] userinfo = user.Login(pUserName, pPassword, tid, pdate, db);
                    if (userinfo[1] == 1)//操作员
                    {
                        return RedirectToAction("Index/" + userinfo[0] + "/" + pdate, "OperatorRealtimeTransaction");

                        //  return RedirectToAction("Index/" + userinfo[0] + "/" + pdate, "Welcome");

                    }
                    else if (userinfo[1] == 2)//经理，管理员
                    {
                        //   return RedirectToAction("Index/" + userinfo[0] + "/" + pdate, "OperatorRealtimeTransaction");//这个路由路径需要修改
                        return RedirectToAction("Index/" + userinfo[0] + "/" + pdate, "Welcome");
                    }
                    else
                    {
                        return View();
                    }
                }
                else
                {
                    return Redirect("/Home/Index");
                }
            }
            else
            {
                return Redirect("/Home/Index");
            }
        }
        public ActionResult About()
        {
            return View();
        }

        public ActionResult Busy()
        {
            return View();
        }

        public ActionResult HasNonePower()
        {
            return View();
        }


    }
}
